/**
 * Created by lxh on 2018/1/14.
 */
import React,{PureComponent} from 'react';
import { Button } from 'antd';
import { Link } from 'dva/router';
import Result from '../../../components/Result';
import styles from '../../User/RegisterResult.less';
import {connect} from 'dva';
import {routerRedux} from 'dva/router';

const title = <div className={styles.title}>操作成功</div>;
@connect((state)=>({
    orderMange:state.orderManage
}))
export default class OptionResult extends PureComponent{
    state={
        orderMange:{},
        record:{},
    }


    handleReturn = () => {
        const {dispatch} = this.props;
        dispatch(routerRedux.push('/order/orderManage'));
    }

    componentDidMount() {
        this.props.dispatch({
            type:'orderManage/fetch',
            payload:{order_sn:this.props.orderMange.FormData.order_sn},
            callback:(response)=>{
                if(response.result===0){
                    this.state.orderMange=response.resultData.orderManage;
                }else{
                    message.error("失败")
                }
            }
        })
        // this.timer = setInterval(function(){
        //         this.handleReturn();
        // }.bind(this), 5000);

    }
    componentWillUnmount() {
        // 如果存在this.timer，则使用clearTimeout清空。
        // 如果你使用多个timer，那么用多个变量，或者用个数组来保存引用，然后逐个clear
        this.timer && clearInterval(this.timer);
    }
    render(){
        const {orderId}=this.props.orderMange;
        // const {orderManage:{data}} = this.props;
        const actions = (
            <div className={styles.actions}>
                <Button size="large" type="primary" onClick={this.handleReturn}>返回订单管理界面</Button>
                <Button size="large" ><Link to={{pathname:'/order/orderDetails',state:{record:this.props.orderMange.FormData}}}>返回订单详情页面</Link></Button>
            </div>
        );

        return (
            <Result
                className={styles.registerResult}
                type="success"
                title={title}
                description="请选择操作，5S之后将自动跳转到订单管理界面"
                actions={actions}
                style={{ marginTop: 56 }}
            />
        )
    }
}
